package org.min.file;

import java.io.*;
import java.util.concurrent.CountDownLatch;

/**
 * @author by Jiang Xiaomin
 * @date : 2024/9/12.
 * @desrc:
 */
public class FileUtils {
    public static void main(String[] args) {
        readFileByLine();

        /*try {
            final CountDownLatch latch = new CountDownLatch(6);
            SysThreadPool.getThreadPoolExecutor().execute(() -> {
                iItemContentService.copy(id, drawingId);
                latch.countDown();
            });
            SysThreadPool.getThreadPoolExecutor().execute(() -> {
                EFile eFile = new EFile();
                BeanUtils.copyProperties(fileDTO, eFile);
                iDrawingPropertyService.copy(id, drawingId, eFile);
                latch.countDown();
            });
            SysThreadPool.getThreadPoolExecutor().execute(() -> {
                itemService.copy(id, drawingId);
                latch.countDown();
            });

            SysThreadPool.getThreadPoolExecutor().execute(() -> {
                iHandleService.copy(id, drawingId);
                latch.countDown();
            });

            SysThreadPool.getThreadPoolExecutor().execute(() -> {
                iItemPropertyService.copy(id, drawingId);
                latch.countDown();
            });
            SysThreadPool.getThreadPoolExecutor().execute(() -> {
                iFlowDirectionService.copy(id, drawingId);
                latch.countDown();
            });
            latch.wait();
            
       *//* EFile eFile = fileMapper.getById(drawingId);
        iDrawingPropertyService.copy(id, drawingId, eFile);
        itemService.copy(id, drawingId);
        iHandleService.copy(id, drawingId);
        iItemPropertyService.copy(id, drawingId);
        iFlowDirectionService.copy(id, drawingId);
        iItemContentService.copy(id, drawingId);*//*
        } catch (Exception e) {
            log.error("copy 发生错误....");
            e.printStackTrace();
            rollBack(drawingId);
            throw new RuntimeException();
        }*/
    }

    /**
     * 一行行的读取文件
     */
    private static void readFileByLine() {
        String filePath = "C:\\Users\\59561\\Desktop\\pidcad.sql"; // 替换为你的文件路径
        String id = "s-d4aeaa18-9e1d-4f14-a301-da599f134580";
        String outputFile = "C:\\Users\\59561\\Desktop\\盛洪\\现场数据库\\复制问题\\sql\\" +id + ".sql"; // 输出文件路径

        try (BufferedReader reader = new BufferedReader(new FileReader(filePath));
             BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile))) {
            String line;
            Integer lineNum = 1;
            while ((line = reader.readLine()) != null) {
                // 处理读取到的每一行
                if (line.contains(id)){
                    writer.write(line);
                    writer.newLine();
                }
                lineNum++;
            }
            System.out.println(" 读取行数：" + lineNum);
            System.out.println("读取完成");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    
}
